package com.yeshine.opendata.service.impl;

import com.yeshine.opendata.core.ServiceBase;
import com.yeshine.opendata.dao.IRoleDao;
import com.yeshine.opendata.entity.Role;
import com.yeshine.opendata.service.IRoleService;
import com.yeshine.opendata.utils.PageResult;
import com.yeshine.opendata.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by taohj on 2014/9/3.
 */

@Service
public class RoleServiceImpl extends ServiceBase<Role> implements IRoleService {


    @Autowired
    private IRoleDao dao;

    @Override
    public Result<Role> create(Role role) {
        if(dao.insert(role) > 0){
            return new Result<Role>("新增成功");
        }else {
            return  new Result<Role>(false,"新增失败");
        }

    }

    @Override
    public Result<Role> remove(Role role) {

        if(dao.delete(role) > 0){
            return new Result<Role>("删除成功");
        }else {
            return  new Result<Role>(false,"删除失败");
        }


    }

    @Override
    public Result<Role> modify(Role role) {
        if(dao.update(role) > 0){
            return new Result<Role>("更新成功");
        }else {
            return  new Result<Role>(false,"更新失败");
        }

    }

    @Override
    public Result<Role> getById(Integer id) {
        return new Result<Role>(dao.selectById(id));
    }

    @Override
    public Result<Role> getList(Role role) {
        return new Result<Role>(dao.selectList(role));
    }

    @Override
    public Result<Role> getByPage(PageResult<Role> pageResult) {
        pageResult.setRows(dao.selectbyPage(pageResult));
        return new Result<Role>(pageResult);
    }
}
